package com.xmall.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmall.auth.dao.SysResourceCategoryMapper;
import com.xmall.auth.entity.SysResourceCategory;
import com.xmall.auth.service.ISysResourceCategoryService;
import com.xmall.common.config.PlatformContant;
import com.xmall.common.config.PojoUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 资源分类表 服务实现类
 * </p>
 *
 * @author liuzh
 * @since 2020-06-14
 */
@Service
public class SysResourceCategoryServiceImpl extends ServiceImpl<SysResourceCategoryMapper, SysResourceCategory> implements ISysResourceCategoryService {
    @Autowired
    SysResourceCategoryMapper sysResourceCategoryMapper;

    @Override
    public boolean saveSysResourceCategory(SysResourceCategory sysResourceCategory) {
        PojoUtils.setSysProperties(sysResourceCategory, PlatformContant.OpType.insert);
        return save(sysResourceCategory);
    }

    @Override
    public boolean updateSysResourceCategory(Long id, SysResourceCategory sysResourceCategory) {
        SysResourceCategory oldSysResourceCategory = getById(id);
        BeanUtils.copyProperties(sysResourceCategory, oldSysResourceCategory);
        PojoUtils.setSysProperties(oldSysResourceCategory, PlatformContant.OpType.update);
        boolean update = update(
                oldSysResourceCategory,
                new QueryWrapper<SysResourceCategory>()
                        .lambda().eq(SysResourceCategory::getId, id)
        );
        return update;
    }

    @Override
    public boolean deleteSysResourceCategory(Long id) {
        boolean b = removeById(id);
        return b;
    }

    @Override
    public SysResourceCategory getSysResourceCategory(Long id) {
        SysResourceCategory sysResourceCategory = getById(id);
        return sysResourceCategory;
    }
}
